package com.design.patterns.list.state.eg;

/**
 * 发放奖品
 *
 * @author Wangzhiwen
 */
public class DispenseState implements ActivityState {

    private final ActivityContext context;

    public DispenseState(ActivityContext context) {
        this.context = context;
    }

    @Override
    public void deduct() {
        System.out.println("已扣除过积分");
    }

    @Override
    public boolean lottery() {
        System.out.println("当前状态不能抽奖");
        return false;
    }

    @Override
    public void grant() {
        if (context.getCount() <= 0) {
            System.out.println("很遗憾！奖品池已无奖品了");
            context.setState(context.dispenseOutState);
            return;
        }
        // 流转状态为已发放
        System.out.println("请去领取奖品");
        context.setCount(context.getCount() - 1);
        context.setState(context.noState);
    }
}
